package com.ruoyi.mobile.project.sms.service;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.ruoyi.db.sms.domain.SmsGrouponRules;
import com.ruoyi.db.sms.domain.query.SmsGrouponRulesQueryVo;
import com.ruoyi.db.sms.mapper.SmsGrouponRulesMapper;
import com.ruoyi.mobile.project.utils.GrouponConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WxSmsGrouponRulesService
{
    @Autowired
    private SmsGrouponRulesMapper grouponRulesMapper;

    public int createRules(SmsGrouponRules rules)
    {
        return 0;
    }

    /**
     * 根据ID查找对应团购项
     * @author 严方亚
     * @date 2020-05-17
     * @param id
     * @return
     */
    public SmsGrouponRules findById(Long id)
    {
        return grouponRulesMapper.selectSmsGrouponRulesById(id);
    }

    /**
     * 查询某个商品关联的团购规则
     *
     * @param goodsId
     * @return
     */
    public List<SmsGrouponRules> queryByGoodsId(Long goodsId)
    {
        SmsGrouponRulesQueryVo smsGrouponRulesQueryVo = new SmsGrouponRulesQueryVo();
        smsGrouponRulesQueryVo.setGoodsId(goodsId);
        smsGrouponRulesQueryVo.setStatus(GrouponConstant.RULE_STATUS_ON);
        return grouponRulesMapper.selectSmsGrouponRulesList(smsGrouponRulesQueryVo);
    }

    public int countByGoodsId(Long goodsId)
    {
        return 0;
    }

    public List<SmsGrouponRules> queryByStatus(Short status)
    {
        return null;
    }

    /**
     * 获取首页团购规则列表
     *
     * @param page
     * @param limit
     * @return
     */
    public List<SmsGrouponRules> queryList(Integer page, Integer limit)
    {
        return queryList(page, limit, null, null);
    }

    public List<SmsGrouponRules> queryList(Integer page, Integer limit, String sort, String order)
    {
        SmsGrouponRulesQueryVo grouponRulesQueryVo = new SmsGrouponRulesQueryVo();
        grouponRulesQueryVo.setStatus(GrouponConstant.RULE_STATUS_ON);
        grouponRulesQueryVo.setOrder(order);
        grouponRulesQueryVo.setSort(sort);

        PageHelper.startPage(page, limit);
        return grouponRulesMapper.selectSmsGrouponRulesList(grouponRulesQueryVo);
    }

    /**
     * 判断某个团购规则是否已经过期
     *
     * @return
     */
    public boolean isExpired(SmsGrouponRules rules)
    {
        return true;
    }

    /**
     * 获取团购规则列表
     *
     * @param goodsId
     * @param page
     * @param size
     * @param sort
     * @param order
     * @return
     */
    public List<SmsGrouponRules> querySelective(String goodsId, Integer page, Integer size, String sort, String order)
    {
        return null;
    }

    public void delete(Long id)
    {

    }

    public int updateById(SmsGrouponRules grouponRules)
    {
        return 0;
    }
}
